from spass.api.api_warehouse import (wget_assignment_version_file,
                                     wget_assignment_version_test,
                                     wget_assignment_version,
                                     wget_assignment_team,
                                     wget_assignment)
from spass.core.error import error
import sys, os
from optparse import OptionParser

def callback_export_assignment_version_file(option, opt_str, value, parser):
    setattr(parser.values, option.dest, value)
    wget_assignment_version_file(parser.values.file[0], parser.values.file[1], parser.values.file[2], parser.values.file[3], parser.values.file[4])

def callback_export_assignment_version_test(option, opt_str, value, parser):
    setattr(parser.values, option.dest, value)
    wget_assignment_version_test(parser.values.test[0], parser.values.test[1], parser.values.test[2], parser.values.test[3], parser.values.test[4])

def callback_export_assignment_version(option, opt_str, value, parser):
    setattr(parser.values, option.dest, value)
    wget_assignment_version(parser.values.version[0], parser.values.version[1], parser.values.version[2], parser.values.version[3])

def callback_export_assignment_team(option, opt_str, value, parser):
    setattr(parser.values, option.dest, value)
    wget_assignment_team(parser.values.team[0], parser.values.team[1], parser.values.team[2])

def callback_export_assignment(option, opt_str, value, parser):
    setattr(parser.values, option.dest, value)
    wget_assignment(parser.values.assignment[0], parser.values.assignment[1])

def export(argv):
    parser = OptionParser()
    parser.set_usage("""spass export <options>""")
    parser.add_option("--assignment", action="callback", callback=callback_export_assignment, type="string", nargs=2, dest="assignment",
                      help="Exports an assignment directory from the warehouse. ARG : <assignment ID> <DIR target>")
    parser.add_option("--assignment-team", action="callback", callback=callback_export_assignment_team, type="string", nargs=3, dest="team",
                      help="Exports an assignment team directory from the warehouse. ARG : <assignment ID> <team ID> <DIR target>")   
    parser.add_option("--assignment-ver", action="callback", callback=callback_export_assignment_version, type="string", nargs=4, dest="version",
                      help="Exports an assignment team version directory from the warehouse. ARG : <assignment ID> <team ID> <version ID> <DIR target>")
    parser.add_option("--assignment-ver-file", action="callback", callback=callback_export_assignment_version_file, type="string", nargs=5, dest="file",
                      help="Exports an assignment team version file from the warehouse. ARG : <assignment ID> <team ID> <version ID> <file name> <target>")
    parser.add_option("--assignment-ver-test", action="callback", callback=callback_export_assignment_version_test, type="string", nargs=5, dest="test",
                      help="Exports an assignment team version test result from the warehouse. ARG : <assignment ID> <team ID> <version ID> <test name> <target>")
					  
    (options, args) = parser.parse_args(argv)
    return 0
